package Controller;

import Pojo.Snack;
import Service.impl.SnackServiceImpl;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class SnackQueryByIdServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        try {
            String snackid = request.getParameter("snackid");
            SnackServiceImpl snackService=new SnackServiceImpl();
            Snack snack=snackService.QueryById(Integer.parseInt(snackid));
            response.getWriter().print(JSON.toJSONString(snack));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
